﻿using System;
using System.Collections.Generic;
using System.Data;
using System.Data.SqlClient;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace ConsoleApp2
{
    class Program
    {
        static void Main(string[] args)
        {
            var conString = "server=DESKTOP-RQLSIQ5\\SQLEXPRESS;database=Admin10;uid=sa;pwd=20010719";

            SqlConnection sqlConnection = new SqlConnection(conString);
            sqlConnection.Open();
           //方法一
            SqlCommand command = new SqlCommand("select * from Times",sqlConnection);
            Console.WriteLine("{0}\t{1}\t\t{2}", "Id","PresentTime","CreationTime");
            var reader = command.ExecuteReader();
            while (reader.Read())
            {
                Console.WriteLine("{0}\t{1}\t{2}",reader["Id"],reader["PresentTime"],reader["CreationTime"]);
            }
            sqlConnection.Close();


            //方法二
            DataTable table = new DataTable();
            var cmdString = "select * from Times";
            SqlDataAdapter dataAdapter = new SqlDataAdapter(cmdString, conString);
            dataAdapter.Fill(table);
            Console.WriteLine();
            Console.WriteLine("{0}\t{1}\t\t{2}", "Id", "PresentTime", "CreationTime");
            foreach (DataRow row in table.Rows)
            {
                Console.WriteLine("{0}\t{1}\t{2}",row["Id"],row["PresentTime"],row["CreationTime"]);
            }
        }
    }
}
